<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<title><spring:message code="message.listForm.qiYeChanPinKuGuanLi"/> <spring:message code="message.lable.compdrugprofileStd"/> <spring:message code="message.listForm.shengChanQiYe"/></title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="renderer" content="webkit">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
	<link href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
	<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
	<style type="text/css">
	   .inf{
		   position:fixed;
		   top:150px;
		   right:35px;
		   width:150px;
		   height:250px;
		   background-color:#3c8dbc;
		   z-index:999;
		}
		p.infTitle{
		   color:#fff;
		   margin-left:10px;
		   margin-top:8px;
		   line-height:10px;
		}
		p.infWord{
		  color:#e1ebf3;
		  margin-left:10px;
		  line-height:12px;
		}
		.opacity50 { /* 75% opaque */
		    opacity:0.75;
		    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=75)";
		    filter:alpha(opacity=75);
		    zoom:1
		}
		#shclNs {
		   position:fixed;
		   left:0px;
           top:0px;
           width:100%;
           height:100%;
           opacity:0.75;
           -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=75)";
           filter:alpha(opacity=75);
           background-color: gray;
           margin:0px;
           padding:0px;
           z-index:999999;
           background:url('${ctx}/lib/img/loading.gif') no-repeat center center;
		}
	</style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame" style="height:100%;">
    
    <section class="content-header">
	    <h1><spring:message code="message.lable.compdrugprofileSTDmanage"/></h1>
	    <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.compdrugprofileStd"/></a></li>
        </ol>
    </section>
    
	<section class="content" style="min-height:0px;">
		<div class="box box-success">
			<div class="box-body">
				<div class="input">
				 	<div class="textalign1"><spring:message code="message.listForm.ziZhiMingCheng"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchProfileName" name="searchProfileName" placeholder="<spring:message code="message.listForm.ziZhiMingCheng"/>" />
                    </div>
                    <div class="textalign1"><spring:message code="message.listForm.ZiZhiBianMa"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchProfileCode" name="searchProfileCode" placeholder="<spring:message code="message.listForm.ZiZhiBianMa"/>" />
                    </div>
					 <div class="textalign1"><spring:message code="message.listForm.shenHeZhuanTai"/><spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                        <select id="auditStatus" name="auditStatus" class="textinput">
                            <option value=""><spring:message code="message.select.option"/></option>
                            <option value="3"><spring:message code="message.select.weitijiao"/></option>
                            <option value="0"><spring:message code="message.select.weishenhe"/></option>
                            <option value="1"><spring:message code="message.jqGrid.cz.audit"/><spring:message code="message.jieSuan.tongGuo"/></option>
                            <option value="2"><spring:message code="message.jqGrid.cz.audit"/><spring:message code="message.listForm.buTongGuo"/></option>
                        </select>
                    </div>
                    <div class="textalign1" >
					<button  id="selectSerch"  type="button" onclick="searchDrugProfile();" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
				</div>
				</div>
			</div>
		</div>
	</section>
	
	<section id="listPanel" class="content" style="min-height:0px;padding-top:0px;">
        <div id="scrollPanel" class="box box-primary" style="height:100%;overflow-y:auto;">
            <div id="wrapper" style="overflow:hidden;">
                <div id="content" style="overflow:hidden;"></div>
			</div>
        </div>
	</section>
	
	<section class="content-header" style="position:fixed;bottom:0px;left:0px;right:0px;">
        <div class=" box box-warning bottongroup">
            <ms:btn url="/compDrugProfile/addSC.html"><a id="addNew" class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></a></ms:btn>
             <ms:btn url="/compDrugProfile/submitCompProfile.html"><button type="button" class="btn btn-primary btn-sm" id="submitDicCompType" onclick="submitCompProfile();"><spring:message code="message.button.submitSpacing"/></button></ms:btn>
            <a href="javascript:history.go(-1)" class="btn btn-danger btn-sm"><spring:message code="message.button.getBackSpacing"/></a>
        </div>
    </section>
    
    <div class="opacity50 inf">
		<p class="infTitle"><b><spring:message code="message.listForm.yaoPinBianMa"/><spring:message code="message.yanZheng.maoHao"/></b></p>
		<p class="infWord">${drugInfo.drugCode}</p>
		<p class="infTitle"><b><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></b></p>
		<p class="infWord">${drugInfo.qualityspecName}</p>
		<p class="infTitle"><b><spring:message code="message.listForm.jiXing"/><spring:message code="message.yanZheng.maoHao"/></b></p>
		<p class="infWord">${drugInfo.formName}</p>
		<p class="infTitle"><b><spring:message code="message.listForm.guiGe"/><spring:message code="message.yanZheng.maoHao"/></b></p>
		<p class="infWord">${drugInfo.specName}</p>
		<p class="infTitle"><b><spring:message code="message.listForm.shengChanQiYe"/><spring:message code="message.yanZheng.maoHao"/></b></p>
		<p class="infWord">${drugInfo.compName}</p>
	</div>
	
	<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header bg-primary">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h5 class="modal-title" id="exampleModalLabel"><spring:message code="message.lable.DICyaoPinZiZhi"/></h5>
                </div>
                <form id="form" action="${ctx}/compDrugProfile/saveSelfDrugProfile.html" method="post" enctype="multipart/form-data">
                <div class="modal-body">
                    <div class="form-group form-group-xs">
                        <label for="recipient-name" class="control-label"><span class="required">*</span><spring:message code="message.listForm.mingCheng"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="" >
                            <input type="text" class="form-control" id="profileName" name="profileName" placeholder="<spring:message code="message.lable.compdrugprofileSTDname"/>" maxlength="128">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="recipient-name" class="control-label"><span class="required">*</span><spring:message code="message.listForm.yaoPinZiZhiLeiXing"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="" >
                           <select class="form-control" id="profileType" name="profileType">
                             <option value=""><spring:message code="message.select.option"/></option>
                             <c:if test="${typeList != null}">
                                 <c:forEach items="${typeList}" var="type">
                                    <option value="${type.id}">${type.name}</option>
                                 </c:forEach>
                             </c:if>
                           </select>
                        </div>
                    </div>
                    <div class="form-group form-group-xs" >
                        <label for="recipient-name" class="control-label"><span class="required">*</span><spring:message code="message.listForm.tuPian"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <a id="url"  href="" ><img id="url2" class="img-responsive"  border="0" src="" onerror="this.src='${ctx}/upload/image/nothing.jpg'" width="50px" height="50px"/></a>
                        <div class="">
                            <input id="acctApprovalPicDir" name="profile" type="file" style="display:inline-none;" />
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label><span class="required">*</span><spring:message code="message.listForm.youXiaoQiKaiShiRiQi"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="">
                              <input class="form-control" type="text" name="profileStarttime" id="createTimeBegin" placeholder="yyyy-MM-dd"
                              onFocus="var endDate=$dp.$('createTimeEnd');WdatePicker({maxDate:'#F{$dp.$D(\'createTimeEnd\')}'})" maxlength="25"/>
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label><span class="required">*</span><spring:message code="message.listForm.youXiaoQiJieZhiRiQi"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="">
                             <input class="form-control" type="text" name="profileEndtime" id="createTimeEnd" placeholder="yyyy-MM-dd" maxlength="25"
                                onFocus="WdatePicker({minDate:'#F{$dp.$D(\'createTimeBegin\')}'})" />
                        </div>
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm"><spring:message code="message.lable.remark"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <textarea class="form-control"  placeholder="<spring:message code="message.lable.remark"/>" id="remark" name="remark" maxlength="512"></textarea>
                   </div>
                   <input type="hidden" id="compprofileId" name="compProfileId" />
                   <input type="hidden" name="prodId" value="${prodId}" />
                </div>
                </form>
                <div class="modal-footer"   >
                    <button type="button" class="btn btn-primary btn-sm" id="submitDicCompType" onclick="save();"><spring:message code="message.button.saveSpacing"/></button>
                    <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal" id="closeDicCompType"><spring:message code="message.button.closeSpacing"/></button>
                </div>
            </div>
        </div>
    </div>
	
	<div id="shclNs"></div>
    
    <script id="test" type="text/html">
        {{each rows as row i}}
            <div class="col-xs-6 col-lg-4 hei" style="height:450px;">
                <div class="wrapper2 ">
                    <a id=""  href="javascript:showImg('{{row.profilePicAddr}}','{{row.profileName}}');" ><img class="img-responsive" border="0" src="${ctx}/{{row.profilePicShortcutAddr}}" onerror="this.src='${ctx}/upload/image/nothing.jpg'" /></a>
                    <div class="row" style=" margin-left: -12;margin-left: -23px; visibility:{{if row.auditStatus == 2 || row.auditStatus == 3}}visible{{else}}hidden{{/if}};" >
						<div class="col-md-12">
                            <p class="pull-left imgButton">
                                <ms:btn url="/compDrugProfile/editSC.html"> <button type="button" class="btn btn-primary btn-sm" style="margin-left: 1px;" id="submitDicCompType" onclick="edit('{{row.compprofileId}}','{{row.profileCode}}','{{row.profileName}}','{{row.profileType}}','{{row.profileStarttime}}','{{row.profileEndtime}}','{{row.profilePicAddr}}','{{row.remark}}');" style="margin-left:10px"><spring:message code="message.button.editSpacing"/></button></ms:btn>
                                <input type="checkbox" class="checkbox" name="compprofileIds" value="{{row.compprofileId}}" /input>  
                            </p>
                        </div>
                    </div>
                    <div class="row" style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.bianHao"/><spring:message code="message.yanZheng.maoHao"/><span class="productInfo" name="profileCode" >{{row.profileCode}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.mingCheng"/><spring:message code="message.yanZheng.maoHao"/><span class="productInfo" name="profileName" >{{row.profileName}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.leiXing"/><spring:message code="message.yanZheng.maoHao"/><span class="productInfo" name="profileType" >{{row.firstLevelIndiName}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                 <div class="productInfo" >&nbsp;<spring:message code="message.listForm.youXiaoQi"/><spring:message code="message.yanZheng.maoHao"/><span class="productInfo" name="profileTime" >&nbsp;{{row.profileStarttime}}&nbsp;&nbsp;-&nbsp;&nbsp;{{row.profileEndtime}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.lable.status"/><spring:message code="message.yanZheng.maoHao"/><span class="productInfo" name="status" >{{row.status | formatStatus}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.lable.remark"/><spring:message code="message.yanZheng.maoHao"/><span class="productInfo" name="remarks" >{{row.remark}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.shenHeZhuanTai"/><spring:message code="message.yanZheng.maoHao"/><span class="productInfo" name="auditStatus" >{{row.auditStatus | formatAuditStatus}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.shenHeBeiZhu"/><spring:message code="message.yanZheng.maoHao"/><span class="productInfo" name="auditRemark" >{{row.auditRemark}}</span></div>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        {{/each}}
    </script>

    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    	$("#searchProfileName").focus();//加载页面光标在第一个查询框内
    	
    	 //绑定回车     id="selectSerch"   
    	   $('#searchProfileName,#searchProfileCode,#auditStatus').bind('keydown', function(event) {
    	       if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
    	           $('#selectSerch').click();
    	       }
    	   }); 
    
        var opType = 0; //  0新增，1编辑
        var records = 0;//总条目
        var postData = {"rows":6,"page":1,"prodId":"${prodId}"};//rows 一页展示多少条   page当前页数
    
        function resizeListHeight() {
        	var windowHeight = $(window).height() || 0;
            var topHeight = $("#listPanel").position().top || 0;
            var bottomHeight = 75;
            var height = windowHeight - topHeight - bottomHeight;
            height = height < 0 ? 0 : height;
            $("#listPanel").height(height);
        }
        
        function getList(postData){
	       	$("#shclNs").show();
	       	$.post('${ctx}/compDrugProfile/getCompSelfDrugProfileList.html', postData, function(result) {
		       	if (result.success) {
			       	$("#shclNs").hide();
			       	var html = template('test', result);
			       	$('#content').append(html);
			       	records = result.records;  //总条数
		       	}
	       	}, "json");
       	}
        
        function searchDrugProfile() {
        	var profileCode = $.trim($("#searchProfileCode").val());
        	var profileName = $.trim($("#searchProfileName").val());
        	var auditStatus = $.trim($("#auditStatus").val());
        	postData["profileCode"] = profileCode;
        	postData["profileName"] = profileName;
        	postData["auditStatus"] = auditStatus;
        	postData["page"] = 1;
        	$('#content').children().remove();
        	getList(postData);
        }
        
        //提交
        function submitCompProfile() {
        	 var len = $("[name='compprofileIds']:checked").length
             if (len<1){
            	 $.alert('<spring:message code="message.listForm.gouXuanYiTiao"/><spring:message code="message.lable.DICyaoPinZiZhi"/>','warn');
            	 return;
             }
        	 var list = [];
        	 $("[name='compprofileIds']:checked").each(function(){
 		    	list.push({"compProfileId":$(this).val()});
 		    })
	    	$.HN.message.confirm("<spring:message code="message.listForm.yiXuanZe"/>"+len+"<spring:message code="message.listForm.ge"/>,<spring:message code="message.jieSuan.queDingTiJiaoMa"/>", '', '').on(function (e) {
	    		if (e) {
                    $.post("${ctx}/compDrugProfile/submitCompProfile.html", {
                    	"array" : json.jsonToString(list)
                    }, function(result) {
                        if (result.success) {
                        	searchDrugProfile();
                            $.alert("<spring:message code="message.jieSuan.tiJiaoChengGong"/>", "success");
                        } else {
                            $.alert("<spring:message code="message.jieSuan.tiJiaoShiBai"/>", "error");
                        }
                    }, "json");
                 }
	  	  });
        	
        	
        }  
         
        function edit(compprofileId, profileCode,profileName,profileType,profileStarttime,profileEndtime,profilePicAddr,remarks,compId) {
            opType = 1;
            $('#compprofileId').val(compprofileId);
            $('#profileCode').val(profileCode);
            $('#profileName').val(profileName);
            $("#profileType").val(profileType);
            $('#createTimeBegin').val(profileStarttime);
            $('#createTimeEnd').val(profileEndtime);
            $('#remark').val(remarks);
            
            $('#url2').attr("src","${ctx}/"+profilePicAddr);
            $('#url').attr("href","javascript:showImg('"+profilePicAddr+"','"+profileName+"');");
            
            $('#acctApprovalPicDir').val("");
            $('#exampleModalLabel').html("<spring:message code="message.lable.compdrugprofileSTDedit"/>");
            $('#url').show();
            $('#exampleModal').modal({
                keyboard : true
            });
        }

        function validate() {
            var profileName = $.trim($("#profileName").val());
            if (profileName == null || profileName == "") {
                $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.lable.compdrugprofileSTDname"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return false;
            }
            
            var profileType = $.trim($("#profileType").val());
            if (profileType == null || profileType == "") {
                $.alert("<spring:message code="message.select.option"/><spring:message code="message.listForm.yaoPinZiZhiLeiXing"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return false;
            }
            
            if (opType == 0) {  //  新增时必须上传资质图片
                var acctApprovalPicDir = $.trim($("#acctApprovalPicDir").val());
                if (acctApprovalPicDir == null || acctApprovalPicDir == "") {
                    $.alert("<spring:message code="message.HN.alert.pleaseInputYPZZIMG"/>", "warn");
                    return false;
                }
            }
            
            var createTimeBegin = $.trim($("#createTimeBegin").val());
            if (createTimeBegin == null || createTimeBegin == "") {
                $.alert("<spring:message code="message.select.option"/><spring:message code="message.listForm.youXiaoQiKaiShiRiQi"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return false;
            }

            var createTimeEnd = $.trim($("#createTimeEnd").val());
            if (createTimeEnd == null || createTimeEnd == "") {
                $.alert("<spring:message code="message.select.option"/><spring:message code="message.listForm.youXiaoQiJieZhiRiQi"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return false;
            }
            return true;
        }
        
        //保存
        function save() {
            if (validate()) {
                $.HN.message.confirm('<spring:message code="message.HN.alert.OkSaveYESorNO"/>', '<spring:message code="message.HN.alert.tiShiXinXi"/>', '<spring:message code="message.lable.OKYES"/>').on(function(e) {
                    if (e) {
                        var url = "${ctx}/compDrugProfile/addSC.html";
                        if(compprofileId !=null && compprofileId != ""){    
                        	url = "${ctx}/compDrugProfile/editSC.html"; 
                        }
                       /*  $("#form").attr("action",url ); */
                        $("#form").ajaxSubmit({
                        	url:url,
                            dataType : "json",
                            timeout : 10000,
                            success : function(result, statusText) {
                                if (result.success) {
                                	searchDrugProfile();
                                    $('#exampleModal').modal('hide');
                                    $.alert("<spring:message code="message.HN.alert.success"/>", "success");
                                } else {
                                    $.alert(result.msg || "<spring:message code="message.HN.alert.xinZenShiBai"/>", "error");
                                }
                            }
                        });
                    }
                });
            }
        }
        
        function showImg(imgPath, profileName) {
            var url = "${ctx}/acctInfo/toImg.html";
            $.HN.dialog.open({
                "id" : "showImg",
                "title" : profileName,
                "url" : url,
                "data" : {
                    "imgPath" : imgPath
                },
                "width" : 800,
                "height" : 400
            });
        }
    
        $(document).ready(function() {
        	template.helper('formatStatus', function(data) {
        	    return data == 1 ? "<spring:message code="message.button.start"/>" : "<spring:message code="message.button.stop"/>";
        	});

        	template.helper('formatAuditStatus', function(data) {
        	    if (data == 0) {
        	        return "<spring:message code="message.select.weishenhe"/>";
        	    } else if (data == 1) {
        	        return "<spring:message code="message.jqGrid.cz.audit"/><spring:message code="message.jieSuan.tongGuo"/>";
        	    } else if (data == 2) {
        	        return "<spring:message code="message.jqGrid.cz.audit"/><spring:message code="message.listForm.buTongGuo"/>";
        	    } else {
        	        return "<spring:message code="message.select.weitijiao"/>";
        	    }
        	});
        	
        	$('#addNew').click(function() {
                opType = 0;
                $('#compprofileId').val("");
                $('#profileCode').val("");
                $('#profileName').val("");
                $("#profileType").val("");
                $('#createTimeBegin').val("");
                $('#createTimeEnd').val("");
                $('#remark').val("");
                $('#acctApprovalPicDir').val("");
                $('#exampleModalLabel').html("<spring:message code="message.lable.compdrugprofileSTDadd"/>");
                $('#url').hide();
                $('#exampleModal').modal({
                    keyboard : true
                });
            });
        	
        	$(window).resize(function() {
        		resizeListHeight();
        	});
        	
        	var timer = null;
        	
        	$("#scrollPanel").scroll(function() {
        		clearTimeout(timer);
        		var scrollTop = $(this).scrollTop();
        		var height = $("#wrapper").height() - $("#listPanel").height();
        		timer = setTimeout(function() {
        			if (scrollTop >= height) {
                        postData.page++;
                        if (postData.page <= Math.ceil(records / postData.rows)) {
                            getList(postData);
                        } 
                    }
        		}, 100);
        	});
        	
        	resizeListHeight();
        	getList(postData);
        });
    
        
    </script>

</body>
</html>

